home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / music / protracker / src.lzh / ptcompacter.s < prev    next >
Text File  |  1991-12-18  |  2KB  |  83 lines

  1. ;******** EQUAL BYTES COMPACTER ********
  2.  
  3. Main    move.l    DataPtr(PC),a0    ;From ptr.
  4.     move.l    #$50000,a1    ;To ptr.
  5.     move.l    DataLen(PC),d7    ;Length
  6.     move.w    Lowest(PC),d3
  7.     moveq    #0,d4        ; Clear count
  8.  
  9. EqLoop    move.b    (a0)+,d0    ; Get a byte
  10.     cmp.b    d0,d3        ; Same as compacter code?
  11.     beq    JustCode    ; Output JustCode
  12.     cmp.l    #1,d7
  13.     beq    endskip
  14.     cmp.b    (a0),d0        ; Same as previous byte?
  15.     beq    Equal        ; Yes, it was equal
  16. endskip    tst.w    d4        ; Not equal, any equal buffered?
  17.     bne    FlushBytes    ; Yes, output them
  18. PutByte    move.b    d0,(a1)+    ; output byte
  19.     moveq    #0,d4
  20. NextByte
  21.     move.w    d0,$dff180    ; Flash colors
  22.     subq.l    #1,d7        ; Subtract 1 from length
  23.      bne    EqLoop        ; Loop until length = 0
  24.  
  25.     tst.w    d4        ; Any buffered bytes?
  26.     beq    endok        ; No, goto end
  27.     cmp.w    #3,d4        ; More than 4?
  28.     bhs    FourOrMore2    ; Yes, skip
  29. NotFour2
  30.     move.b    d0,(a1)+    ; Output byte
  31.     dbf    d4,NotFour2    ; Loop...
  32.     bra    endok        ; Goto end
  33. FourOrMore2
  34.     move.b    d3,(a1)+    ; Output compacter code
  35.     move.b    d4,(a1)+    ; Output count
  36.     move.b    d0,(a1)+    ; Output byte
  37. endok    sub.l    DataPtr(pc),a1    ; Subtract start from end
  38.     move.l    a1,d0        ; Store compacted length
  39.     move.l    DataLen,d1
  40.     move.l    d1,d2
  41.     sub.l    d0,d1
  42.     mulu    #100,d1
  43.     divu    d2,d1
  44.     move.l    d2,$50000-4
  45.     rts            ; Return...
  46.  
  47. ;-------------------------------
  48.  
  49. JustCode
  50.     move.b    d3,(a1)+    ; Output compacter code
  51.     clr.b    (a1)+        ; Output zero
  52.     move.b    d3,(a1)+    ; Output compacter code
  53.     bra    NextByte    ; Do next byte
  54.  
  55. Equal    move.b    d0,d1
  56.     addq.w    #1,d4        ; Add one to equal-count
  57.     cmp.w    #255,d4        ; 255 or more?
  58.     bhs    FlushBytes    ; Yes, flush buffer
  59.     bra    NextByte    ; Do next byte
  60.  
  61. FlushBytes
  62.     cmp.w    #3,d4        ; 4 or more
  63.     bhs    FourOrMore    ; Yes, output codes
  64. NotFour    move.b    d1,(a1)+    ; Output byte
  65.     dbf    d4,NotFour    ; Loop...
  66.     moveq    #0,d4        ; Zero count
  67.     bra    NextByte    ; Another byte
  68. FourOrMore
  69.     move.b    d3,(a1)+    ; Output compacter code
  70.     move.b    d4,(a1)+    ; Output count
  71.     move.b    d1,(a1)+    ; Output byte
  72.     moveq    #0,d4        ; Zero count
  73.     addq.b    #1,d0
  74.     bra    NextByte    ; Do next byte
  75.  
  76. DataPtr:    dc.l $40000
  77. DataLen:    dc.l 8008
  78. CompLen:    dc.l 0
  79. Lowest:        dc.w 181
  80.  
  81. >extern "df1:raw/ptsetup2.raw",$40000
  82.  
  83.